/**
 * 
 */
package de.cbf.cam.map2d.listeners;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Widget;

import de.cbf.cam.map2d.shapes.Shape;

/**
 * @author Stefan Alter
 *
 */
public class ObjectPaintListener implements PaintListener {
	private List<Shape> terrainObjects = new ArrayList<Shape>();
	protected float zoomFactor;
	/**
	 * 
	 */
	public ObjectPaintListener(float zoomFactor) {
		this.zoomFactor = zoomFactor;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
	 */
	@Override
	public void paintControl(PaintEvent event) {
		Widget widget =event.widget;
		if (widget instanceof Scrollable) {
			Scrollable scrollable = (Scrollable) widget;
			Rectangle clientArea = scrollable.getClientArea();
			drawTerrain(event.gc,clientArea);
		}		 
	}

	private void drawTerrain(GC gc, Rectangle clientArea) {
		for(int i =0;i<terrainObjects.size();i++){
			terrainObjects.get(i).drawObject(gc, clientArea);
		}
	}
	
	public void addObject(Shape object){
		terrainObjects.add(object);
	}
	public void removeObject(Shape object){
		terrainObjects.remove(object);
	}
}
